package com.aries.remoteplus.core;

import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

import android.content.Intent;
import android.os.Bundle;

import com.illposed.osc.OSCPortOut;

public class CommonFuncs {
	
	public static OSCPortOut getPortOutByIntent(Intent dataIntent)
	{
		OSCPortOut portOut = null;
		
		if (dataIntent != null)
		{
			Bundle dataBundle = dataIntent.getExtras();
			
			String ipAddres 	= dataBundle.getString("ipAddress");
//			int tcpPort			= dataBundle.getInt("tcpPort");
			int udpPort			= dataBundle.getInt("udpPort");
			
			try
			{
				portOut = new OSCPortOut(InetAddress.getByName(ipAddres), udpPort);
				
				return portOut;
			} catch (SocketException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (UnknownHostException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return null;
	}
}
